#!/usr/bin/python
# -*- coding: utf-8 -*-
# @version        : 1.0
# @Create Time    : 2024/8/17 10:03:49
# @File           : crud.py
# @IDE            : PyCharm
# @desc           : 派工 - 增删改查

from sqlalchemy.ext.asyncio import AsyncSession
from core.crud import DalBase
from . import models, schemas
from apps.base.external.crud import ExternDal


class TaskAssignUsersDal(DalBase):
    def __init__(self, db: AsyncSession):
        super(TaskAssignUsersDal, self).__init__()
        self.db = db
        self.model = models.DCTaskAssignUsers
        self.schema = schemas.TaskAssignUsersSimpleOut

    async def get_emp_groups(self, **params):
        async for resp in ExternDal().get_emp_teams(**params):
            return resp["list"], int(resp["total_count"])

    async def get_emp_users(self, **params):
        if not params.get("team") and not params.get("team_code"):
            return [], 0
        async for resp in ExternDal().get_emp_users(**params):
            return resp["list"], int(resp["total_count"])
